#include <iostream>
#define MAX_CHAR 40
using namespace std;

int getArr(int num, int (&numArr)[MAX_CHAR]);
int pow(int base, int number);
int delNum(int numArr[MAX_CHAR], int bit, int numBit);

int main(){
	int num;
	cin >> num;
	int count;
	cin >> count;
	int numArr[MAX_CHAR];
	//get number Bit
	for(int i = 1; i <= count; i++){
		int numBit = getArr(num, numArr);
		int min = num;
		for(int j = 1; j <= numBit; j++){
			int temp = delNum(numArr, j, numBit);
			if(temp < min) min = temp;
		}
		num = min;
	}
	cout << num << endl;
}


int getArr(int num, int (&numArr)[MAX_CHAR]){
	int i = 1;
	while(num != 0){
		numArr[i] = num % 10;
		num = num / 10;
		i++;
	}
	return i - 1;
}

int pow(int base, int number){
	if(number == 0) return 1;
	int a = base;
	while(number > 1){
		a *= base;
		number--;
	}
	return a;
}

int delNum(int numArr[MAX_CHAR], int bit, int numBit){
	int num = 0;
	for(int i = 1; i <= numBit - 1; i++){
		if(i < bit)
			num += numArr[i] * pow(10, i - 1);
		else
			num += numArr[i + 1] * pow(10, i - 1);
	}
	return num;
}
